using System.IO;
using System.Web;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.FileProviders;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using DreamHome.Models;

namespace DreamHome.Pages;

public class MultiformModel : PageModel
{
    [BindProperty]
    public string Name { get; set; } = string.Empty;

    [BindProperty]
    public string Password { get; set; } = string.Empty;

    public string Msg { get; set; } = string.Empty;

    public IQueryable<UserInfo> UserInfo { get; set; } = default!;


    private readonly UserInfoContext _context;

    public MultiformModel(UserInfoContext context)
    {
        _context = context;
        UserInfo = context.UserInfo ?? default!;
    }

    public void OnPostHandler(string name, string key)
    {
        var a = from i in UserInfo
            where i.Name == name && i.Key == key
            select i;
        Msg = a.Count().ToString();
    }

    public void OnGet(string? name)
    {
        if (_context.UserInfo != null)
        {
            UserInfo = _context.UserInfo;
        }
    }
}